<template>
  <div id="order">
    <el-page-header class="el-header" @back="goBack" title="返回首页"></el-page-header>
    <h1>线下律师服务订单生成与支付页面</h1>
    <el-steps :space="200" :active="active" finish-status="finish" align-center="true">
      <el-step title="确认订单" icon="el-icon-s-claim"></el-step>
      <el-step title="支付订单" icon="el-icon-s-finance"></el-step>
      <el-step title="订单完成" icon="el-icon-success"></el-step>
    </el-steps>
    <el-card class="box-card" shadow="always">
      <el-row :gutter="20" align-center="true">
        <el-col :span="16">
          <el-card>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
              <el-form-item label="订单名称" prop="name" disabled="true">
                <el-input v-model="ruleForm.name"></el-input>
              </el-form-item>
              <el-form-item label="订单类型" prop="orderType">
                <el-select v-model="ruleForm.orderType" placeholder="请选择订单类型">
                  <el-option label="线下咨询" value="offline"></el-option>
                  <el-option label="线上图文/电话咨询" value="online"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="咨询时间" required>
                <el-col :span="11">
                  <el-form-item prop="date1">
                    <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date1" style="width: 100%;"></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col class="line" :span="2">-</el-col>
                <el-col :span="11">
                  <el-form-item prop="date2">
                    <el-time-picker placeholder="选择时间" v-model="ruleForm.date2" style="width: 100%;"></el-time-picker>
                  </el-form-item>
                </el-col>
              </el-form-item>
              <el-form-item label="是否匿名" prop="anonymous">
                <el-switch v-model="ruleForm.anonymous"></el-switch>
              </el-form-item>
              <el-form-item label="法律类型" prop="type">
                <el-checkbox-group v-model="ruleForm.type">
                  <el-checkbox label="民事类" name="type"></el-checkbox>
                  <el-checkbox label="经济类" name="type"></el-checkbox>
                  <el-checkbox label="刑事行政" name="type"></el-checkbox>
                  <el-checkbox label="涉外" name="type"></el-checkbox>
                  <el-checkbox label="公司专项" name="type"></el-checkbox>
                  <el-checkbox label="其他非讼" name="type"></el-checkbox>
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="问题描述" prop="desc">
                <el-input type="textarea" v-model="ruleForm.desc"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
                <el-button @click="resetForm('ruleForm')">重置</el-button>
              </el-form-item>
            </el-form>
          </el-card>
        </el-col>
        <el-col :span="8" >
            <el-card>
              <span class="card-title">律师信息</span>
              <el-row :gutter="20" align-center="true">
                <el-col :span="12">
                  <img src="https://imgt.66law.cn/upload/t/202009/11/171657179.jpg" class="image" alt="律师图片">
                </el-col>
                <el-col :span="12">
                  <div>
                    {{ lawyerMsg }}
                  </div>
                </el-col>
              </el-row>
            </el-card>
            <el-card shadow="always" v-if="formisDone">
              <h3>付款码</h3>
              <el-image class="eimage" :src="imageSrc" fit="contain" lazy></el-image>
              <div class="price">付费金额：{{ price }}</div>
              <el-button @click="goToTest">我已支付</el-button>
            </el-card>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
import imageUrl from '../../assets/erweima.png'
import axios from "axios"
export default {
  name: "CreateOrder",
  data() {
    return {
      formisDone: false,
      // 付款金额
      price: 0,
      // 二维码
      imageSrc: imageUrl,
      // 临时律师信息存放处
      lawyerMsg: "张丽丽，河南益仟律师事务所执业律师，2014年毕业于郑州大学法学院。自毕业以来一直从事法律事务，期间办理过劳动争议、离婚、民间借贷、交通事故以及合同纠纷案件。",
      // 表单信息
      ruleForm: {
        name: 'XXX律师XX咨询服务',
        orderType: '',
        date1: '',
        date2: '',
        anonymous: false,
        type: [],
        resource: '',
        desc: '',
      },
      // 步骤条进度
      active: 0,
      // 表单未填写时提示
      rules: {
        name: [
          { required: true, message: '订单名称', trigger: 'blur' },
          { min: 3, max: 30, message: '长度在 3 到 30 个字符', trigger: 'blur' }
        ],
        orderType: [
          { required: true, message: '请选择订单类型', trigger: 'change' }
        ],
        date1: [
          { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
        ],
        date2: [
          { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        ],
        type: [
          { type: 'array', required: true, message: '请至少选择一个相关法律类型', trigger: 'change' }
        ],
        resource: [
          { required: true, message: '请选择活动资源', trigger: 'change' }
        ],
        desc: [
          { required: true, message: '请填写咨询问题', trigger: 'blur' }
        ]
      }
    };
  },
  computed: {

  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post("http://localhost:8080/order/addOrder", {
            order: {
              order_id: '',
              user_id: '1',
              user_name: this.ruleForm.name,
              lawyer_id: '张丽丽',
              order_descrip: this.ruleForm.desc,
              order_type: this.ruleForm.orderType,
              done: true,
              start: this.ruleForm.date1,
              end: this.ruleForm.date1
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
      // 步骤条进行下一步
      this.next();
      this.price = Math.ceil(Math.random()*10) * 100
      this.formisDone = true
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.formisDone = false
    },
    // 步骤条前进
    next() {
      console.log(this.ruleForm.orderType + "   " + this.ruleForm.type)
      if (this.active++ > 2) this.active = 0;
    },
    goBack() {
      window.location = "index.html"
    },
    goToTest() {
      window.location = "http://localhost:8080/websocket/张三"
    },
  }
}
</script>

<style scoped>

.el-header {
  color: #2c3e50;
}
.card-title {
  font-size: x-large;
  font-weight: bolder;
}
.image {
  width: 100%;
  display: flex;
}
.eimage {
  width: 160px;
  height: 160px;
}
</style>